package vn.edu.saigontech.ncms.service.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import vn.edu.saigontech.ncms.model.englishtest.Candidate;
import vn.edu.saigontech.ncms.model.englishtest.TestRegister;
import vn.edu.saigontech.ncms.service.TestRegisterService;

@SuppressWarnings("unchecked")
public class TestRegisterServiceImpl extends HibernateGenericService<TestRegister, Long>
		implements TestRegisterService {

	public Collection<TestRegister> findRecently() {
		Criteria criteria = this.createCriteria();
		criteria.addOrder(Order.desc("id"));
		criteria.setMaxResults(5);
		return criteria.list();
	}

	@Override
	public List<TestRegister> findByCandidate(Candidate candidate) {
		Criteria criteria = this.createCriteria();
		criteria.addOrder(Order.desc("date"));
		criteria.add(Restrictions.eq("candidate", candidate));
		return criteria.list();
	}
}